
/********************************************
*
*
********************************************/


#ifdef __cplusplus
#if __cplusplus
extern "C"{
#endif
#endif /* __cplusplus */

#include <stdio.h>
#include <stdarg.h>
#include <unistd.h>

#include "d_base.h"

typedef VOID (* OSAL_LOG_WRITE_HOOK)(UINT32 ulLevel,
                                     UINT32 ulErrId,
                                     const CHAR * pFile,
                                     UINT32 ulLine,
                                     const CHAR * pFormat,
                                     ...);

OSAL_LOG_WRITE_HOOK m_pfnOsalLogWriteHook = NULL;

VOID OSAL_LogWrite(const char * func,
                   const char * file,
                   UINT32 uiLine,
                   const char * pformat,
                   ...)
{
    char     nbuf[DMS_MAX_FORMAT_LEN];
    va_list  argptr;
    int      cnt;

    if( m_pfnOsalLogWriteHook )
    {
        va_start(argptr, pformat);
        cnt = vsnprintf(nbuf ,DMS_MAX_FORMAT_LEN, pformat, argptr);
        va_end(argptr);

        m_pfnOsalLogWriteHook(2,1,file,uiLine,"%s",nbuf);
    }
    else
    {
        snprintf(nbuf,DMS_MAX_FORMAT_LEN,"[DMS_LOG]:func(%s),file(%s),line(%d):\n",func,file,uiLine);

        cnt = strlen(nbuf);

        va_start(argptr, pformat);
        cnt = vsnprintf(nbuf + cnt ,DMS_MAX_FORMAT_LEN - cnt,pformat, argptr);
        va_end(argptr);

        cnt = strlen(nbuf);

        write(2,nbuf,cnt);
    }
}

VOID DMS_OsalLogWirteHookSet(VOID * pfnLogWriteFunc )
{
    m_pfnOsalLogWriteHook = (OSAL_LOG_WRITE_HOOK)pfnLogWriteFunc;
}

#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif /* __cplusplus */

